package com.hsogoo.collate.service;

import com.hsogoo.collate.configuration.SftpConfig;
import com.hsogoo.collate.constants.Constant;
import com.hsogoo.collate.domain.SftpBean;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author huangsaigang
 * Created @2019-10-29.
 */
@Slf4j
@Service
@Setter
public class CollateDownloadService {

    @Autowired
    private SftpConfig sftpConfig;

    public void downloadCollateFile(String targetServer, String targetCollateFile, String localFilePath){
        //获取服务器信息
        SftpBean sftpBean = sftpConfig.getSftpBeanMap().get(targetServer);
        if (sftpBean == null) {
            sftpBean = sftpConfig.getSftpBeanMap().get(Constant.DEFAULT_TARGET_SERVER);
        }
        if (sftpBean == null) {
            log.error("target server [{}] not find ...", targetServer);
            throw new RuntimeException();
        }
//        try {
//            FileTools.downLoadFileBySftp(targetCollateFile, localFilePath, sftpBean);
//        } catch (IOException e) {
//            log.error("download collate file exception", e);
//            throw new RuntimeException("download collate file exception", e);
//        }
        log.info("download collate file [{}] completed [{}]！", targetCollateFile, localFilePath);
    }

}
